﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TuongLaiDangCho.DTO;
using System.Data;
using System.Data.OleDb;

namespace TuongLaiDangCho.DAO
{
    class LenLichDAO
    {
        public static DataTable LoadTimeTable(LenLichDTO ttb)
        {
            string sql = "Select * from LENLICH Where NgayThang=#" + ttb.NgayThang.ToShortDateString() + "#";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            cn.Close();
            return dt;
        }

        public static void InsertTimeTable(LenLichDTO ttb)
        {
            string sql="Insert into LenLich(NgayThang,Gio,NoiDung) values(#"+ttb.NgayThang.ToShortDateString()+"#,'"+ttb.Gio+"','"+ttb.NoiDung+"')";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }

        public static void UpdateTimeTable(LenLichDTO ttb)
        {
            string sql="Update LenLich set Gio='"+ttb.Gio+"' , NoiDung='"+ttb.NoiDung+"' where ID="+ttb.ID.ToString()+"";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }

        public static void DeleteTimeTable(LenLichDTO ttb)
        {
            string sql = "Delete From LenLich Where ID=" + ttb.ID.ToString() + "";
            OleDbConnection cn = DataProvider.OpenCn();
            OleDbCommand cm = new OleDbCommand(sql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
        }
    }
}
